﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Xww.Text {
    [Serializable]
    public class RegexReplacer : IEquatable<RegexReplacer> {
        public RegexReplacer(Regex regex, string output) {
            REGEX = regex;
            Replacement = output;
        }

        ///<summary>替换子的源表达式</summary>
        public Regex REGEX { get; private set; }
        ///<summary>用来替换的格式（$1,$2...代表分组匹配结果）</summary>
        public string Replacement { get; set; }

        #region IEquatable<RegexReplacer> 成员

        public bool Equals(RegexReplacer other) {
            if (other == null) { return false; }
            bool rst = this.Replacement == other.Replacement;
            rst = rst && (this.REGEX.ToString() == other.REGEX.ToString());
            rst = rst && (this.REGEX.Options == other.REGEX.Options);
            return rst;
        }

        #endregion
    }
}
